home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / latex209 / contrib / misc / subfigure.sty < prev    next >
Text File  |  1993-05-12  |  13KB  |  315 lines

  1. %$% subfigure.sty
  2. %$% Subfigure/table command for use with the LaTeX figure environment.
  3. %$% $Header: subfigure.sty,v 1.6 93/05/13 12:58:34 sdc Exp $
  4. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  5. %%% @LaTeX-style-file{
  6. %%%    Author              = "Steven Douglas Cochran",
  7. %%%    Version             = "1.6",
  8. %%%    Date                = "13 May 1993",
  9. %%%    Time                = "12:58:34 EDT",
  10. %%%    Filename            = "subfigure.sty",
  11. %%%    Address             = "Digital Mapping Laboratory
  12. %%%                           School of Computer Science
  13. %%%                           Carnegie-Mellon University
  14. %%%                           5000 Forbes Avenue
  15. %%%                           Pittsburgh, PA 15213-3891
  16. %%%                           USA",
  17. %%%    Telephone           = "(412) 268-5654",
  18. %%%    FAX                 = "(412) 681-5739",
  19. %%%    checksum            = "32478 314 1501 13334",
  20. %%%    Email               = "sdc+@CS.CMU.EDU (Internet)",
  21. %%%    CodeTable           = "ISO/ASCII",
  22. %%%    Keywords            = "LaTeX, float, figure, table",
  23. %%%    Supported           = "yes",
  24. %%%    Abstract            = "LaTeX document-style option for
  25. %%%                           providing support for the inclusion of
  26. %%%                           small `sub' figures and tables.  It
  27. %%%                           simplifies the positioning, captioning
  28. %%%                           and labeling of them within a single
  29. %%%                           figure or table environment.",
  30. %%%    DocString           = "The checksum field above contains a CRC-16
  31. %%%                           checksum as the first value, followed by
  32. %%%                           the equivalent of the standard UNIX wc
  33. %%%                           (word count) utility output of lines,
  34. %%%                           words, and characters.  This is produced
  35. %%%                           by Robert Solovay's checksum utility."
  36. %%% }
  37. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  38. %%% $Log:    subfigure.sty,v $
  39. %$%  Revision 1.6  93/05/13  12:58:34  sdc
  40. %$%  Changed to use the \thefigure macro in building the referenced
  41. %$%  label.  The old form caused a problem when used with the
  42. %$%  report.sty as pointed out by Andrew Anselmo
  43. %$%  (anselmo@cumesb.mech.columbia.edu).  Also modified to restrict
  44. %$%  the scope of the subfigure \label to the body of the subfigure.
  45. %$%  Added \@thesubfigure to allow a separate labeling of the
  46. %$%  subfigure in the figure and in the text.  By default it is the
  47. %$%  same as \thesubfigure with space appended.  Added some hooks to
  48. %$%  print the subfigure captions to the list-of-figures file if
  49. %$%  desired.  Finally, added the corresponding support for sub-tables
  50. %$%  as well as sub-figures.  NOTE: the optional caption is now a
  51. %$%  moving argument and any fragile commands that appear in the
  52. %$%  caption must be preceded by a \protect (just like that of the
  53. %$%  \caption command).
  54. %$%  
  55. %$%  Revision 1.5  92/08/11  23:13:12  sdc
  56. %$%  Fixed a bug which caused an problem with captions that contained 
  57. %$%  expressions like \sqrt;  This was pointed out by Tom Scavo
  58. %$%  (scavo@cie.uoregon.edu).  A separate bug was fixed which caused
  59. %$%  different sized captions to be misaligned;  This problem was
  60. %$%  pointed out by Simon Marshall (S.Marshal@Hull.ac.uk).  Also
  61. %$%  cleaned up the code a mite and *changed* the figure spacing so that
  62. %$%  if no optional section is given, then the figure is only followed
  63. %$%  by \subfigbottomskip and not that plus (\subfigcapskip + \strut
  64. %$%  height).  This should make it easier to adjust spacing as desired.
  65. %$%  
  66. %$%  Revision 1.4  92/06/27  10:40:34  sdc
  67. %$%  Added a hack to allow the \label command to be used within the
  68. %$%  body of the subfigure giving a reference label in the form
  69. %$%  \arabic{thefigure}\thesubfigure.  Added standard file header for
  70. %$%  style. 
  71. %$%  
  72. %$%  Revision 1.3  90/10/22  17:04:28  cochran
  73. %$%  Changed test for empty caption inside of \@subfigure to compare
  74. %$%  tokens and not the caption vs. \@empty.  The former (incorrect)
  75. %$%  test caused an error when the first two letters of the caption
  76. %$%  were the same.
  77. %$%
  78. %$%  Revision 1.2  89/08/30  07:18:29  cochran
  79. %$%  Added a separate bottom margin and expanded the comments.
  80. %$%
  81. %$%  Revision 1.1  88/11/02  11:03:46  cochran
  82. %$%  Initial revision.
  83. %$%
  84. %$%  05 Mar 86  cochran@dworkin.usc.edu (USC-IRIS)
  85. %$%  Created.
  86. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  87. %$% Usage:  \documentstyle[...,subfigure,...]{...}
  88. %$%
  89. %$%             \subfigure[CAPTIONtext]{FIGUREbox}
  90. %%%
  91. %%% Creates a subfigure box with an optional CAPTION under a FIGURE.
  92. %%% The FIGURE is centered with \subfigtopskip of vertical space added
  93. %%% above.  If there is a CAPTION, then \subfigcapskip vertical space
  94. %%% is added below the FIGURE followed by the CAPTION.  Finally,
  95. %%% \subfigbottomskip of vertical space added at the bottom. 
  96. %%%
  97. %%% If a CAPTION is given (including a null CAPTION `[]') then the
  98. %%% subfigure is labeled with a counter formatted by the macro
  99. %%% `\thesubfigure' which returns `(a)', `(b)', etc.  If desired,
  100. %%% this macro may be redefined.  The counter used for labeling the
  101. %%% subfigures is `subfigure' and is incremented for each subfigure
  102. %%% regardless of whether a CAPTION was printed.
  103. %%%
  104. %$%             \subfigure[CAPTIONtext]{FIGUREbox}
  105. %%%
  106. %%% The subtable command is symmetric to the subfigure command defined
  107. %%% above.  
  108. %%%
  109. %%% One example of use is to surround the figure in a tabular
  110. %%% environment (this preserves alignment along the bottom of the
  111. %%% figures when the figures and/or the captions are different
  112. %%% heights):                     
  113. %%%
  114. %%%   \def\goodgap{%                         *---------*  
  115. %%%     \hspace{\subfigtopskip}%             |  ..   . |   *---------* 
  116. %%%     \hspace{\subfigbottomskip}}          |  .   .  |   | . .  .  | 
  117. %%%   ...                                    | .. . .  |   | .  . .. | 
  118. %%%   \begin{figure}%                        *---------*   *---------*   
  119. %%%     \centering                            (a) First     (b) Second  
  120. %%%     \begin{tabular[t]{c}%                               Figure
  121. %%%       \subfigure[First]{...}\goodgap            
  122. %%%       \subfigure[Second Figure]{...}\\         *---------*
  123. %%%       \subfigure[Third]{\label{3figs-c}...}%   | . .. .  |
  124. %%%     \end{tabular}%                             | . .. .  |
  125. %%%     \caption{Three Subfigures.}                *---------*
  126. %%%     \label{3figs}                               (c) Third
  127. %%%   \end{figure}                          Figure 1. Three Subfigures.  
  128. %%%   ...                                
  129. %%%   Figure~\ref{3figs} contains        Figure 1 contains two top `sub-
  130. %%%   two top `subfigures' and           figures' and Figure 1(c).
  131. %%%   Figure~\ref{3figs-c}.
  132. %%%
  133. %%% A second example is to change the way that the subfigures are labeled
  134. %%% and to have the subfigure captions printed in the list-of-figures.
  135. %%%
  136. %%%   \def\thesubfigure{\thefigure.\arabic{subfigure}}
  137. %%%   \makeatletter
  138. %%%     \def\@thesubfigure{\thesubfigure:\space}
  139. %%%     \let\p@subfigure\relax
  140. %%%   \makeatother
  141. %%%   ...
  142. %%%   \setcounter{lofdepth}{2}
  143. %%%   \listoffigures
  144. %%%   ...
  145. %%%   \begin{figure}%
  146. %%%     \begin{center}%
  147. %%%       \subfigure[First]{%         *--------------*  *--------------*  
  148. %%%         \label{fig:first}%        |  ..   .  .   |  | . ... .. . . | 
  149. %%%         ...}%                     |  .  .   .  . |  | .  .  . . .. | 
  150. %%%       \goodgap                    | .. . .  . .  |  | . . . .. ..  |
  151. %%%      \subfigure[Second]{%         *--------------*  *--------------*  
  152. %%%         \label{fig:second}% 
  153. %%%         ...}%                        1.1: First        1.2: Second
  154. %%%     \end{center}%
  155. %%%     \caption{Two Subfigures.}          Figure 1. Two Subfigures.
  156. %%%   \end{figure}                  
  157. %%%   ...                             See subfigures 1.1 and 1.2. 
  158. %%%   See subfigures \ref{fig:first} 
  159. %%%   and \ref{fig:second}.
  160. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  161.  
  162. %%%
  163. %%%  Setup hooks and constants
  164. %%%
  165.  
  166. %%
  167. %% Subfigure values
  168. %%
  169. \newcounter{subfigure}[figure]          % Subfigure counter.
  170. \def\thesubfigure{(\alph{subfigure})}   % Generate CAPTION label (text).
  171. \def\@thesubfigure{\thesubfigure\space} % Generate CAPTION label (figure).
  172. \def\p@subfigure{\thefigure}            % Figure number for \label.
  173.  
  174. \let\ext@subfigure\ext@figure           % Default SubFigure file extension.
  175. \newcounter{lofdepth}                   % LOF depth counter.
  176. \setcounter{lofdepth}{1}                % Default is to NOT print an LOF line.
  177. \def\l@subfigure{%                      % How to print an LOF subfigure line.
  178.   \@dottedxxxline{\ext@subfigure}{2}{3.9em}{2.3em}}
  179.  
  180. %%
  181. %% Subtable values
  182. %%
  183. \newcounter{subtable}[table]            % Subtable counter.
  184. \def\thesubtable{(\alph{subtable})}     % Generate CAPTION label (text).
  185. \def\@thesubtable{\thesubtable\space}   % Generate CAPTION label (figure).
  186. \def\p@subtable{\thetable}              % Figure number for \label.
  187.  
  188. \let\ext@subtable\ext@table             % Default SubTable file extension.
  189. \newcounter{lotdepth}                   % LOT depth counter.
  190. \setcounter{lotdepth}{1}                % Default is to NOT print an LOT line.
  191. \def\l@subtable{%                       % How to print an LOT subtable line.
  192.   \@dottedxxxline{\ext@subtable}{2}{3.9em}{2.3em}}
  193.  
  194. %%
  195. %% Common values (mention of `subfig' in names is for upward compatibility)
  196. %%
  197. \def\subcapsize{\footnotesize} % Size of the CAPTION font.
  198. \def\subfigtopskip{10pt}       % Length from the top of the subfloat
  199.                                %   box to the begining of the FIGURE box.
  200. \def\subfigbottomskip{10pt}    % Length from the bottom of the CAPTION to 
  201.                                %   the bottom of the subfloat.
  202. \def\subfigcapskip{10pt}       % Length from the bottom of the FIGURE box
  203.                                %   to the begining of the CAPTION.
  204. \def\subfigcapmargin{10pt}     % Indentation of the caption from the
  205.                                %   sides of the subfloat box (This
  206.                                %   should always be positive).
  207. \def\@subfigcaptionlist{}      % This is for storing the local list of
  208.                    %   sub-captions.
  209.  
  210.  
  211. %%%
  212. %%% Define the subfigure command
  213. %%%
  214. \def\subfigure{%
  215.   \bgroup                     % Since the figure caption is usually 
  216.     \advance\c@figure\@ne     %   generated later, we must locally
  217.     \refstepcounter{subfigure}%   anticipate the future value of its
  218.     \leavevmode               %   counter. 
  219.     \@ifnextchar [%
  220.       {\@subfloat{subfigure}}%
  221.       {\@subfloat{subfigure}[\@empty]}}
  222.  
  223.  
  224. %%%
  225. %%% Define the subtable command
  226. %%%
  227. \def\subtable{%
  228.   \bgroup                     % Since the table caption is usually 
  229.     \advance\c@table\@ne      %   generated later, we must locally
  230.     \refstepcounter{subtable}%%   anticipate the future value of its
  231.     \leavevmode               %   counter. 
  232.     \@ifnextchar [%
  233.       {\@subfloat{subtable}}%
  234.       {\@subfloat{subtable}[\@empty]}}
  235.  
  236.  
  237. %%%
  238. %%% Define the common subfloat macro
  239. %%%
  240. \def\@subfloat#1[#2]#3{%
  241.     \setbox\@tempboxa \hbox{#3}%
  242.     \@tempdima=\wd\@tempboxa
  243.     \vtop{%
  244.       %% Put the top spacing and the figure in the top box
  245.       \vbox{%
  246.         \vskip\subfigtopskip
  247.         \box\@tempboxa}%
  248.       %% Now skip down and add the caption paragraph
  249.       %%   (unless #2 == \@empty)
  250.       \ifx \@empty#2\relax \else
  251.         %% Add the caption information to the \@subfigcaptionlist.
  252.     \@subcaption{#1}{#2}%
  253.         %% Insert some glue; then measure and insert the caption.
  254.         \vskip\subfigcapskip
  255.         \setbox\@tempboxa \hbox{\subcapsize\csname @the#1\endcsname #2}%
  256.         \@tempdimb=-\subfigcapmargin
  257.         \multiply\@tempdimb\tw@
  258.         \advance\@tempdimb\@tempdima
  259.         \hbox to\@tempdima{%
  260.           \hfil
  261.           \ifdim \wd\@tempboxa >\@tempdimb
  262.             %% Comment too long for one line
  263.             \parbox[t]{\@tempdimb}{\subcapsize\csname @the#1\endcsname #2}%
  264.           \else
  265.             \box\@tempboxa
  266.           \fi
  267.           \hfil}%
  268.       \fi
  269.       %% Finally add the bottom spacing.
  270.       \vskip\subfigbottomskip}%
  271.   \egroup}
  272.  
  273. \def\@subcaption#1#2{%
  274.   \begingroup
  275.     \def\protect{\string\string\string}%
  276.     \xdef\@subfigcaptionlist{%
  277.       \@subfigcaptionlist,%
  278.       {\protect\numberline {\@currentlabel}%
  279.        \noexpand{\ignorespaces #2}}}%
  280.   \endgroup}
  281.  
  282.  
  283. %%%
  284. %%% Generalized wrapper for the \@dottedtocline macro.  This checks for
  285. %%% the level based on the output file (#1) and not using only
  286. %%% \@tocdepth. 
  287. %%%
  288. \def\@dottedxxxline#1#2#3#4#5#6{%
  289.   \ifnum #2>\csname c@#1depth\endcsname \else
  290.     \@dottedtocline{0}{#3}{#4}{#5}{#6}
  291.   \fi}
  292.  
  293.  
  294. %%%
  295. %%% Finally, wrap the \@caption macro to dump any sub-captions saved
  296. %%% after calling the standard \@caption.
  297. %%%
  298. \let\@@caption\@caption
  299.  
  300. \long\def\@caption#1[#2]#3{%
  301.   %% Call the standard \@caption macro.
  302.   \@@caption{#1}[{#2}]{#3}
  303.   %% For each entry in the \@subfigcaptionlist call \addcontentsline.
  304.   \@for \@tempa:=\@subfigcaptionlist \do {
  305.     \ifx\@empty\@tempa\relax \else
  306.       \addcontentsline
  307.         {\csname ext@sub#1\endcsname}%
  308.     {sub#1}%
  309.         {\@tempa}%
  310.     \fi}%
  311.   %% Finally, clean out the \@subfigcaptionlist.
  312.   \gdef\@subfigcaptionlist{}}
  313.  
  314.  
  315.